What is core-js-compat?
The core-js-compat package provides compatibility data for core-js, which is a modular standard library for JavaScript, including polyfills for ECMAScript up to the latest standards. It is useful for developers who need to know which features are available in core-js for a specific version of a browser or Node.js.
What are core-js-compat's main functionalities?
Compatibility Data Retrieval
Retrieve a list of features supported by core-js for a specific environment, such as Chrome 70.
const { list } = require('core-js-compat')({ targets: 'chrome 70' });
Custom Build Generation
Generate a list of core-js modules required to support a specific target, such as Internet Explorer 11, with a specific version of core-js.
const { getModulesListForTargetVersion } = require('core-js-compat');
const modulesList = getModulesListForTargetVersion({ targets: { ie: 11 }, version: '3.6' });
Other packages similar to core-js-compat
babel-polyfill
Babel-polyfill is a package that includes Babel transforms and a polyfill that includes a custom regenerator runtime and core-js. It is similar to core-js-compat in that it provides polyfills for ECMAScript features, but it is less modular and is deprecated in favor of directly including core-js and regenerator-runtime.
es6-shim
The es6-shim package provides polyfills for ECMAScript 6 (also known as ECMAScript 2015) features. It is similar to core-js-compat in providing polyfills, but it is focused only on ES6 features and does not provide the modular approach or the compatibility data that core-js-compat offers.
polyfill-service
The polyfill-service package by Financial Times provides a service that returns a set of polyfills based on the user-agent string of the browser making the request. It is similar to core-js-compat in that it aims to provide polyfills for compatibility, but it does so as a service rather than a package to include in your project.
I highly recommend reading this: So, what's next?
core-js-compat
package contains data about the necessity of core-js
modules and API for getting a list of required core-js modules by browserslist query.
import compat from 'core-js-compat';
const {
list,
targets,
} = compat({
targets: '> 1%',
modules: [
'core-js/actual',
'esnext.array.unique-by',
/^web\./,
],
exclude: [
'web.atob',
],
version: '3.39',
inverse: false,
});
console.log(targets);
targets
option
targets
could be a browserslist
query or a targets object that specifies minimum environment versions to support:
'defaults, not IE 11, maintained node versions';
({
android: '4.0',
bun: '0.1.2',
chrome: '38',
'chrome-android': '18',
deno: '1.12',
edge: '13',
electron: '5.0',
firefox: '15',
'firefox-android': '4',
hermes: '0.11',
ie: '8',
ios: '13.0',
node: 'current',
opera: '12',
'opera-android': '7',
phantom: '1.9',
quest: '5.0',
'react-native': '0.70',
rhino: '1.7.13',
safari: '14.0',
samsung: '14.0',
esmodules: true,
browsers: '> 0.25%',
});
Additional API:
require('core-js-compat/compat')({ targets, modules, version });
require('core-js-compat').compat({ targets, modules, version });
require('core-js-compat/data');
require('core-js-compat').data;
require('core-js-compat/entries');
require('core-js-compat').entries;
require('core-js-compat/modules');
require('core-js-compat').modules;
require('core-js-compat/get-modules-list-for-target-version')('3.39');
require('core-js-compat').getModulesListForTargetVersion('3.39');
If you wanna help to improve this data, you could take a look at the related section of CONTRIBUTING.md
. The visualization of compatibility data and the browser tests runner is available here, the example: